<template>
    <div class="son">
        I am Child2 <br>
        <div v-show="introduce">child1的介绍{{introduce}}</div>
    </div>
</template>
<script setup lang="ts">
import {onMounted, onUnmounted, ref} from 'vue';
import emitter from '@/utils/emitter';
let introduce = ref("");
emitter.on("send-child1",(value:string)=>{
    introduce.value = value;
    console.log("child2接收到了child1的事件=",value);
})

//在组件卸载时解绑send-child1事件
onUnmounted(()=>{
    emitter.off("send-child1")
})

</script>
<style scoped>
.son{
    width: 25vw;
    background-color: rgb(0, 255, 221);
}
</style>